﻿<!DOCTYPE html>

<html lang="zh-cn">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>公共模块配置信息</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
    <style>
        .unoperate {
            display: none;
        }
    </style>
</head>
<body style="background-color:#eeeeee">
    <div class="layui-card" style="margin-left:0px">
        <div class="layui-card-body ">
            <form class="layui-form layui-col-space5" action="~/MLCfgFile/FilterData" method="post">
                <input class="layui-input" value="@ViewBag.path" name="currentDir" id="currentDir" style="display:none" />
                <div class="layui-input-inline layui-show-xs-block">
                    <input class="layui-input" placeholder="请输入文件名(支持模糊匹配)" name="fname" id="fname">
                </div>
                <div class="layui-input-inline layui-show-xs-block">
                    <button class="layui-btn" lay-submit="" lay-filter="sreach">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </form>
        </div>
        <div class="layui-card-header" style="">
            <button class="layui-btn operateBtn unoperate" onclick="uploadCfgFile(this,'@ViewBag.path.Replace(" \\"," /")')">
                <i class="layui-icon">&#xe62f;</i>上传文件
            </button>
        </div>
        <div class="layui-card-body" style="">
            <table class="layui-table layui-form" id="ML" lay-filter="fileList">
            </table>
        </div>
    </div>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/html" id="barDemo">
        <a title="查看" href="javascript:;" lay-event="detail">
            <i class="layui-icon">&#xe63c;</i>查看
        </a>
        <a title="下载" class="operateBtn" href="javascript:;" lay-event="downloadf">
            <i class="layui-icon">&#xe601;</i>下载
        </a>
    </script>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#ML'
                , method: 'get'
                , skin: 'row'
                , even: true
                , page: true
                , url: localStorage.getItem('hosttingaddr') + '/api/CommonCfgFile/index?dir=' + getrequest().dir  //数据接口
                , headers: {
                    user: getCookie("userinfo"),
                    version: getCookie("version")
                }
                , cols: [[ //表头
                    { field: 'name', title: '文件名称', width: 500, sort: true }
                    , { field: 'parentPath', title: '文件路径', width: 500, sort: true }
                    , { field: 'fileSize', title: '文件大小', width: 100, sort: true }
                    , { field: 'createdTime', title: '文件创建时间', width: 180, sort: true }
                    , { field: 'updateTime', title: '文件更新时间', width: 180, sort: true }
                    , { fixed: 'right', title: "操作", width: 150, align: 'center', toolbar: '#barDemo' }
                ]]
                , done: function (res) {
                    if (res.isOperate != 1) {
                        layui.$(".operateBtn").addClass("unoperate");
                    }
                    else {
                        layui.$(".operateBtn").removeClass("unoperate");
                    }
                }

            });

            //监听行工具事件
            table.on('tool(fileList)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                var fileN = data.path;
                if (layEvent == 'detail') {
                    layer.msg('查看操作');
                    //var arr = fileN.split('/');
                    layer.open({
                        type: 2,
                        title: '模块配置文件内容',
                        maxmin: true,
                        shadeClose: true, //点击遮罩关闭层
                        area: ['1600px', '800px'],
                        content: 'commoncfgfiledetail.html' + '?fileName=' + fileN// iframe链接地址
                    });

                } else if (layEvent == 'downloadf') {
                    layer.msg('下载文件');
                    //进行文件下载
                    layui.jquery(location).attr('href', localStorage.getItem('hosttingaddr')+'/api/CommonCfgFile/downloadfile?fileName=' + fileN);
                }
            });
        });
        function uploadCfgFile(obj, pathStr) {
            layer.open({
                type: 2,
                title: '上传模块配置文件',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['600px', '220px'],
                content: '@Url.Action("OpenUploadFile", "CaseElementCfgFile")' + '?pathStr=' + pathStr,// iframe链接地址
                success: function () {
                    //location.reload();
                },
                end: function () {
                    location.reload();
                }
            });
        }
    </script>
</body>
</html>